﻿using System;
using System.IO;
using System.Reflection;

namespace DirectoryCleaner
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Usage();
                return;
            }

            try
            {
                Parser parser = new Parser(args);
                parser.Parse();

                // check if the user is cleaning the relative directory or a specified one
                string directory;
                if (parser.Directory == null)
                {
                    directory = Directory.GetCurrentDirectory();
                }
                else
                {
                    directory = parser.Directory;
                }

                Cleaner cleaner = new Cleaner(directory, parser.Extensions);
                cleaner.Clean();
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        /// <summary>
        /// Displays how to use this thing!
        /// </summary>
        private static void Usage()
        {
            Console.WriteLine("Directory Cleaner version: {0}\n", Assembly.GetExecutingAssembly().GetName().Version);
            Console.WriteLine("clean [options]\n");
            Console.WriteLine("Options:");
            Console.WriteLine("  /dir:<directory>");
            Console.WriteLine("  /preserve:<ext1;ext2;extN>\n");
            Console.WriteLine("Example usage:");
            Console.WriteLine("  clean /preserve:.cs;.csproj");
            Console.WriteLine(@"  clean /dir:c:\MyThesis /preserve:.tex");
        }
    }
}
